<template>
	<view class="container">
		<view class="tui-page-title">修改密码</view>
		<view class="tui-form">
			<view class="tui-view-input">
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input">
						<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
						<input :value="oldpassword" placeholder="请输入旧密码" placeholder-class="tui-phcolor" type="number" maxlength="11" @input="inputOld" />
						<view class="tui-icon-close" v-show="oldpassword" @tap="clearInput(1)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input">
						<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
						<input :value="password" placeholder="请输入新密码" :password="true" placeholder-class="tui-phcolor" type="text" maxlength="40" @input="inputPwd" />
						<view class="tui-icon-close" v-show="password" @tap="clearInput(2)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input">
						<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
						<input :value="password2" placeholder="请再次输入新密码" :password="true" placeholder-class="tui-phcolor" type="text" maxlength="40" @input="inputPwd2" />
						<view class="tui-icon-close" v-show="password2" @tap="clearInput(3)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
			</view>
			<view class="tui-btn-box"><tui-button :disabledGray="true" :disabled="disabled" :shadow="true" shape="circle" @click="save">确认修改</tui-button></view>
		</view>
	</view>
</template>

<script>
export default {
	computed: {
		disabled: function() {
			let bool = true;
			if(this.oldpassword !='' && (this.password2 === this.password) && this.password!=''){
				
				bool = false;
			}
			return bool;
		}
	},
	data() {
		return {
			webUrl:this.tui.apiUrl(),
			oldpassword: '',
			password: '',
			password2: '',
		};
	},
	methods: {
		
		inputOld: function(e) {
			this.oldpassword = e.detail.value;
		},inputPwd: function(e) {
			this.password = e.detail.value;
		},inputPwd2: function(e) {
			this.password2 = e.detail.value;
			
		},
		clearInput(type) {
			if (type == 1) {
				this.oldpassword = '';
			} else if(type == 2){
				this.password = '';
			}else {
				this.password2 = '';
			}
		},
		save(){
			let param = {old:this.oldpassword,password:this.password,password2:this.password2};
			let it = this;
			if(this.password!=this.password2){
				this.tui.toast('两次输入的新密码不正确！')
				return false;
			}
			this.tui.get('user/login/changepwd',param).then(function(res){
				if(res.code ==1){
					it.tui.openPage('../login/login');
				}else{
					it.tui.toast(res.msg)
				}
			})
		},
	}
};
</script>

<style lang="scss">
.container {
	.tui-page-title {
		width: 100%;
		font-size: 48rpx;
		font-weight: bold;
		color: $uni-text-color;
		line-height: 42rpx;
		padding: 110rpx 40rpx 40rpx 40rpx;
		box-sizing: border-box;
	}
	.tui-form {
		padding-top: 50rpx;
		.tui-view-input {
			width: 100%;
			box-sizing: border-box;
			padding: 0 40rpx;
			.tui-cell-input {
				width: 100%;
				display: flex;
				align-items: center;
				padding-top: 48rpx;
				padding-bottom: $uni-spacing-col-base;
				input {
					flex: 1;
					padding-left: $uni-spacing-row-base;
				}
				.tui-icon-close {
					margin-left: auto;
				}
				.tui-btn-send {
					width: 156rpx;
					text-align: right;
					flex-shrink: 0;
					font-size: $uni-font-size-base;
					color: $uni-color-primary;
				}
				.tui-gray {
					color: $uni-text-color-placeholder;
				}
			}
		}
		.tui-btn-box {
			width: 100%;
			padding: 0 $uni-spacing-row-lg;
			box-sizing: border-box;
			margin-top: 80rpx;
		}
	}
}
</style>
